package org.cklxh.waptime;

import org.cklxh.widget.DigitalClock;
import org.waptime.R;

import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class WaptimeHandler extends Handler {

	/**
	 * 接收由RefreshTimeThread线程得到的时间值。
	 * what值表示情况:
	 * 1：显示Toast提示消息。
	 * 2：获取时间成功后，修改界面显示。
	 * 3：获取时间失败后，恢复界面显示。
	 */
	public void handleMessage(Message msg){
		WaptimeActivity waptimeActivity=WaptimeActivity.getActivityObject();
		//Context context=waptimeActivity.getBaseContext();
		switch (msg.what) {
		case 1:
			Toast.makeText(waptimeActivity.getApplicationContext(),(String)msg.obj,Toast.LENGTH_SHORT).show();
			break;
		case 2:
			long time=(Long)msg.obj;
			//设置时间显示框
			DigitalClock internetTimeDC=(DigitalClock)waptimeActivity.findViewById(R.id.internetTime_DC);
			internetTimeDC.setTime(time);
			internetTimeDC.setVisibility(View.VISIBLE);
			
			waptimeActivity.findViewById(R.id.settime_btn).setEnabled(true);
			
			waptimeActivity.findViewById(R.id.internet_default_time_TV).setVisibility(View.GONE);//隐藏默认
			
			waptimeActivity.findViewById(R.id.refresh_pb).setVisibility(View.GONE);//隐藏进度条
			
			//TextView internet_default_time_TV=(TextView)waptimeActivity.findViewById(R.id.internet_default_time_TV);
			//internet_default_time_TV.setText(waptimeActivity.getResources().getString(R.string.internet_default_time));
			break;
		case 3:

			waptimeActivity.findViewById(R.id.refresh_pb).setVisibility(View.GONE);//隐藏进度条
			
			TextView internet_default_time_TV=(TextView)waptimeActivity.findViewById(R.id.internet_default_time_TV);
			internet_default_time_TV.setText(waptimeActivity.getResources().getString(R.string.internet_default_time));
			
			
			break;
		default:
			break;
		}
		
	}
}
